package com.cheng.commonutlis.mvvm.viewmodel;

import android.os.Handler;

import androidx.lifecycle.MutableLiveData;

import com.cheng.commonutlis.mvvm.base.BaseViewModel;
import com.cheng.commonutlis.mvvm.model.User;

public class MvvmVM extends BaseViewModel {

    public final MutableLiveData<User> mUser = new MutableLiveData<>();

    @Override
    protected void onCleared() {
        super.onCleared();
    }
    public void getUser(){
        //模拟 http 获取数据
        Handler handler = new Handler();
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                //DataBind 会帮你做线程切换
                User user = new User("小明", "男", 12);
                mUser.setValue(user);
            }
        };
        handler.postDelayed(runnable, 2000);
    }
}
